<?php

namespace app\common\model\Merchant;
use app\common\model\file\FileModel;
use app\common\model\file\MerchantFileModel;
use app\common\model\setting\SettingStoreFlagModel;
use app\common\model\setting\SettingStorePlatformModel;
use app\common\model\setting\SettingStoreTypeModel;
use think\Model;

class MerchantShopModel extends Model
{
    // 表名
    protected $name = 'merchant_shop';
    // 表主键
    protected $pk = 'id';
    // 关联图片
    public function image()
    {
        return $this->hasOne(MerchantFileModel::class, 'file_id', 'image_id')->append(['file_url'])->where(where_disdel());
    }
    /**
     * 获取图片链接
     * @Apidoc\Field("")
     * @Apidoc\AddField("image_url", type="string", desc="图片链接")
     */
    public function getImageUrlAttr($value, $data)
    {
        return $this['image']['file_url'] ?? '';
    }
    // 关联商家
    public function merchant()
    {
        return $this->hasOne(MerchantModel::class, 'id', 'merchant_id');
    }
    // 关联平台
    public function platform()
    {
        return $this->hasOne(SettingStorePlatformModel::class, 'id', 'setting_store_platform_id');
    }
    // 关联类目
    public function type()
    {
        return $this->hasOne(SettingStoreTypeModel::class, 'id', 'setting_store_type_id');
    }
    // 关联商家
    public function flag()
    {
        return $this->hasOne(SettingStoreFlagModel::class, 'id', 'setting_store_flag_id');
    }
    // 关联店铺分类
    public function group()
    {
        return $this->hasOne(MerchantShopGroupModel::class, 'id', 'shop_group_id');
    }
}
